//
//  Primer_associatedtype_Demo1VC.swift
//  APSwift
//
//  Created by jianbo.pei on 2024/8/16.
//

import UIKit

class Primer_associatedtype_Demo1VC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

}


protocol Container {
    associatedtype Item
    var items: [Item] { get }
    mutating func add(item: Item)
}

struct IntContainer: Container {
    typealias Item = Int
    var items = [Int]()
    
    mutating func add(item: Int) {
        items.append(item)
    }
}

struct StringContainer: Container {
    typealias Item = String
    var items = [String]()
    
    mutating func add(item: String) {
        items.append(item)
    }
}
